package com.xiaochong.tir.manager.service;

import java.util.List;

import com.xiaochong.tir.manager.config.druid.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xiaochong.tir.common.data.mapper.RoleMapper;
import com.xiaochong.tir.common.data.po.Role;
import org.springframework.transaction.annotation.Transactional;

@Service
public class RoleService{
	@Autowired
    private RoleMapper roleMapper;
	
	public PageInfo<Role> listRole(Role role, int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		return new PageInfo<Role>(roleMapper.selectByEntityList(role));
	}
	@Operation
	@Transactional
	public int insertRole(Role role) {
		return roleMapper.insertSelective(role);
	}
	
	public int checkRoleName(Role role) {
		return roleMapper.checkRoleName(role);
	}
	@Operation
	@Transactional
	public int updateRole(Role role,Role old) {
		return roleMapper.updateByPrimaryKeySelective(role);
	}
	
	public Role getRole(Integer id) {
		return roleMapper.selectByPrimaryKey(id);
	}
	
	public List<Role> listAllRole() {
		return roleMapper.selectByEntityList(null);
	}

	public Role selectByPrimaryKey(Integer id) {
		return roleMapper.selectByPrimaryKey(id);
	}
}
